import json

from designad.models import AdvertiserAdType


def getPostJson(adName, adStyle, publisher_ad_types_list, cateList, geoLocList, langList,
              browsersList,operatingSysList, moboileCarriersList,
              devicesList, priceModel, price, maxDailyBudget, alltimeList,
              keywordsList, impressionsEnabled, impressions, minutes,
              ):
    adJson = {}
    # 获取广告类型
    adTye = AdvertiserAdType.objects.filter(name=adStyle)[0]
    if str(adStyle).find('Web Instant Messag') >= 0:
        size = '250x150'
    elif str(adStyle).find('Tab - Direct Link') < 0 \
            and str(adStyle).find('Popunders') < 0 \
            and str(adStyle).find('In-Stream') < 0 \
            and str(adStyle).find('Native Ad') < 0:
        size = str(adStyle.split('-')[1]).strip()
    else:
        size = ''
    if len(langList) <= 0 and len(browsersList) > 0 and len(operatingSysList) > 0 and len(moboileCarriersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(browsersList) <= 0 and len(langList) > 0 and len(operatingSysList) > 0 and len(moboileCarriersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(operatingSysList) <= 0 and len(langList) > 0 and len(browsersList) > 0 and len(operatingSysList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(moboileCarriersList) <= 0 and len(langList) > 0 and len(browsersList) > 0 and len(operatingSysList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(devicesList) <= 0 and len(langList) > 0 and len(operatingSysList) > 0 and len(browsersList) > 0 and len(moboileCarriersList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(browsersList) <= 0 and len(operatingSysList) > 0 and len(moboileCarriersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(operatingSysList) <= 0 and len(browsersList) > 0 and len(moboileCarriersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(moboileCarriersList) <= 0 and len(operatingSysList) > 0 and len(browsersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }

    elif len(langList) <= 0 and len(devicesList) <= 0 and len(operatingSysList) > 0 and len(moboileCarriersList) > 0 and len(browsersList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(browsersList) <= 0 and len(devicesList) <= 0 and len(langList) > 0 and len(operatingSysList) > 0 and len(moboileCarriersList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(browsersList) <= 0 and len(operatingSysList) <= 0 and len(langList) > 0 and len(moboileCarriersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(browsersList) <= 0 and len(moboileCarriersList) <= 0 and len(langList) > 0 and len(operatingSysList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(operatingSysList) <= 0 and len(moboileCarriersList)  <= 0 and len(langList) > 0 and len(browsersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(operatingSysList) <= 0 and len(devicesList) <= 0 and len(langList) > 0 and len(moboileCarriersList) > 0 and len(browsersList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(moboileCarriersList) <= 0 and len(devicesList) <= 0 and len(langList) > 0 and len(operatingSysList) > 0 and len(browsersList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(browsersList) <= 0 and len(devicesList) <= 0 and len(operatingSysList) > 0 and len(moboileCarriersList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(browsersList) <= 0 and len(operatingSysList) <= 0 and len(moboileCarriersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(browsersList) <= 0 and len(moboileCarriersList) <= 0 and len(operatingSysList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(operatingSysList) <= 0 and len(moboileCarriersList) <= 0 and len(browsersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(operatingSysList) <= 0 and len(devicesList) <= 0 and len(moboileCarriersList) > 0 and len(browsersList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(moboileCarriersList) <= 0 and len(devicesList) <= 0 and len(operatingSysList) > 0 and len(browsersList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(browsersList) <= 0 and len(moboileCarriersList) <= 0 and len(devicesList) <= 0 and len(operatingSysList) > 0 and len(langList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(browsersList) <= 0 and len(operatingSysList) <= 0 and len(devicesList) <= 0 and len(langList) > 0 and len(moboileCarriersList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }

    elif len(devicesList) <= 0 and len(operatingSysList) <= 0 and len(moboileCarriersList) <= 0 and len(langList) > 0 and len(browsersList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }

    elif len(langList) <= 0 and len(operatingSysList) <= 0 and len(moboileCarriersList) <= 0 and len(devicesList) <= 0 and len(browsersList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(browsersList) <= 0 and len(operatingSysList) <= 0 and len(devicesList) <= 0 and len(moboileCarriersList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(browsersList) <= 0 and len(moboileCarriersList) <= 0 and len(devicesList) <= 0 and len(operatingSysList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(browsersList) <= 0 and len(moboileCarriersList) <= 0 and len(operatingSysList) <= 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(operatingSysList) <= 0 and len(browsersList) <= 0 and len(moboileCarriersList) <= 0 and len(devicesList) <= 0 and len(langList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(browsersList) <= 0 and len(operatingSysList) <= 0 and len(moboileCarriersList) <= 0 and len(devicesList) <= 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) > 0 and len(browsersList) > 0 and len(operatingSysList) > 0 and len(moboileCarriersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "campaign_type": {
                "type": 0,
                "value": 0
            },
            "advertiser_ad_type": adTye.id,
            "media_storage_template": json.loads(adTye.media_storage_templates)[0],
            "size": size,
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "retargeting": {
                "enabled": False,
                "goals": [{
                    "id": "",
                    "type": 0
                }]
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }

    return adJson


def getPutJson(adName, adStyle, publisher_ad_types_list, cateList, geoLocList, langList,
              browsersList,operatingSysList, moboileCarriersList,
              devicesList, priceModel, price, maxDailyBudget, alltimeList,
              keywordsList, impressionsEnabled, impressions, minutes,
              ):
    adJson = {}
    # 获取广告类型
    adTye = AdvertiserAdType.objects.filter(name=adStyle)[0]
    if len(langList) <= 0 and len(browsersList) > 0 and len(operatingSysList) > 0 and len(
            moboileCarriersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(browsersList) <= 0 and len(langList) > 0 and len(operatingSysList) > 0 and len(
            moboileCarriersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(operatingSysList) <= 0 and len(langList) > 0 and len(browsersList) > 0 and len(
            operatingSysList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(moboileCarriersList) <= 0 and len(langList) > 0 and len(browsersList) > 0 and len(
            operatingSysList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(devicesList) <= 0 and len(langList) > 0 and len(operatingSysList) > 0 and len(
            browsersList) > 0 and len(moboileCarriersList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(browsersList) <= 0 and len(operatingSysList) > 0 and len(
            moboileCarriersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(operatingSysList) <= 0 and len(browsersList) > 0 and len(
            moboileCarriersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(moboileCarriersList) <= 0 and len(operatingSysList) > 0 and len(
            browsersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }

    elif len(langList) <= 0 and len(devicesList) <= 0 and len(operatingSysList) > 0 and len(
            moboileCarriersList) > 0 and len(browsersList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(browsersList) <= 0 and len(devicesList) <= 0 and len(langList) > 0 and len(
            operatingSysList) > 0 and len(moboileCarriersList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(browsersList) <= 0 and len(operatingSysList) <= 0 and len(langList) > 0 and len(
            moboileCarriersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(browsersList) <= 0 and len(moboileCarriersList) <= 0 and len(langList) > 0 and len(
            operatingSysList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(operatingSysList) <= 0 and len(moboileCarriersList) <= 0 and len(langList) > 0 and len(
            browsersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(operatingSysList) <= 0 and len(devicesList) <= 0 and len(langList) > 0 and len(
            moboileCarriersList) > 0 and len(browsersList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(moboileCarriersList) <= 0 and len(devicesList) <= 0 and len(langList) > 0 and len(
            operatingSysList) > 0 and len(browsersList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(browsersList) <= 0 and len(devicesList) <= 0 and len(
            operatingSysList) > 0 and len(moboileCarriersList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(browsersList) <= 0 and len(operatingSysList) <= 0 and len(
            moboileCarriersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(browsersList) <= 0 and len(moboileCarriersList) <= 0 and len(
            operatingSysList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(operatingSysList) <= 0 and len(moboileCarriersList) <= 0 and len(
            browsersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(operatingSysList) <= 0 and len(devicesList) <= 0 and len(
            moboileCarriersList) > 0 and len(browsersList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(moboileCarriersList) <= 0 and len(devicesList) <= 0 and len(
            operatingSysList) > 0 and len(browsersList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(browsersList) <= 0 and len(moboileCarriersList) <= 0 and len(devicesList) <= 0 and len(
            operatingSysList) > 0 and len(langList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(browsersList) <= 0 and len(operatingSysList) <= 0 and len(devicesList) <= 0 and len(
            langList) > 0 and len(moboileCarriersList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }

    elif len(devicesList) <= 0 and len(operatingSysList) <= 0 and len(moboileCarriersList) <= 0 and len(
            langList) > 0 and len(browsersList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }

    elif len(langList) <= 0 and len(operatingSysList) <= 0 and len(moboileCarriersList) <= 0 and len(
            devicesList) <= 0 and len(browsersList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(browsersList) <= 0 and len(operatingSysList) <= 0 and len(
            devicesList) <= 0 and len(moboileCarriersList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(browsersList) <= 0 and len(moboileCarriersList) <= 0 and len(
            devicesList) <= 0 and len(operatingSysList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(browsersList) <= 0 and len(moboileCarriersList) <= 0 and len(
            operatingSysList) <= 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(operatingSysList) <= 0 and len(browsersList) <= 0 and len(moboileCarriersList) <= 0 and len(
            devicesList) <= 0 and len(langList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) <= 0 and len(browsersList) <= 0 and len(operatingSysList) <= 0 and len(
            moboileCarriersList) <= 0 and len(devicesList) <= 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },

            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }
    elif len(langList) > 0 and len(browsersList) > 0 and len(operatingSysList) > 0 and len(
            moboileCarriersList) > 0 and len(devicesList) > 0:
        adJson = {
            "name": adName,
            "media_type": {
                "type": 0,
                "format": json.loads(adTye.media_storage_templates)[0]
            },
            "publisher_ad_types": publisher_ad_types_list,
            "categories": {
                "type": "targeted",
                "elements": cateList
            },
            "countries": {
                "type": "targeted",
                "elements": geoLocList
            },
            "languages": {
                "type": "targeted",
                "elements": langList
            },
            "browsers": {
                "type": "targeted",
                "elements": browsersList
            },
            "operating_systems": {
                "type": "targeted",
                "elements": operatingSysList
            },
            "carriers": {
                "type": "targeted",
                "elements": moboileCarriersList
            },
            "devices": {
                "type": "targeted",
                "elements": devicesList
            },
            "pricing": {
                "model": priceModel,
                "price": price
            },
            "frequency_capping": {
                "enabled": impressionsEnabled,
                "impressions": impressions,
                "minutes": minutes
            },
            "max_daily_budget": maxDailyBudget,
            "idgroup": 0,
            "day_parting": {
                "timezone": "Asia/Shanghai",
                "parting": alltimeList
            },
            "sites": {
                "type": "targeted",
                "elements": [
                    ""
                ]
            },
            "keywords": {
                "type": "targeted",
                "elements": keywordsList
            },
            "optimization_rule": 0
        }

    return adJson